package ngames.com.sushitv.view;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import ngames.com.sushitv.R;

/**
 * Created by Administrator on 2016/4/6.
 */
public class DialogAppLoading extends Dialog {
    private Activity mActivity;
    private View mDialogView;
    private TextView mHintText;
    private ImageView mProgressImv;
    private AnimationDrawable mProgressAnimation;

    public DialogAppLoading(Activity activity) {
        super(activity, R.style.style_custom_dialog);
        mActivity = activity;
        mDialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_loading, null);
        mHintText = (TextView) mDialogView.findViewById(R.id.tv_hint_text);
        mProgressImv = (ImageView) mDialogView.findViewById(R.id.imv_progress);
        mProgressAnimation = (AnimationDrawable) mProgressImv.getDrawable();
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        setContentView(mDialogView);
//        BaseTools.setDialogWidth(activity, this, 0.85f, 0);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void show() {
        super.show();
        mProgressAnimation.start();
    }

    @Override
    public void dismiss() {
        mProgressAnimation.stop();
        super.dismiss();
    }

    public void setHintText(String text) {
        mHintText.setText(text);
        if (!TextUtils.isEmpty(text)) {
            mHintText.setVisibility(View.VISIBLE);
        }
    }
}
